<?php

namespace app\storeapi\validate;

use think\Validate;

class Goods extends Validate
{
    /**
     * 验证规则
     * @var array
     */
    protected $rule = [

        // 商品id
        'goods_id' => [
            'require',
        ],

        // 商品名称
        'goods_name' => [
            'require',
        ],

        // 分类id
        'category_id' => [
            'require',
        ],

        // 图片
        'images' => [
            'require',
            'checkImages'
        ],
        //详情
        'content' => [
            'require',
        ],

    ];


    protected $message  =   [
        'goods_id.require'    => '商品ID不能为空',
        'goods_name.require'   => '请输入商品名称',
        'category_id.require'   => '请选择分类',
        'images.require'        => '请上传图片',
        'images.checkImages'    => '请上传图片',
        'content.require'    => '请输入商品详情',
    ];

    /**
     * 验证场景
     * @var array
     */
    protected $scene = [
        'editInfo' => ['goods_id','goods_name','category_id','content'],
        'addInfo' => ['goods_name','category_id','content'],
        'status' => ['goods_id'],
        'del' => ['goods_id'],
    ];

    protected function checkImages($value) {
        if(is_array($value)){
            return true;
        }else{
            return false;
        }

    }

}
